<!DOCTYPE html>
<html>
	<head>
		<title>-添加/修改</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<!-- 所有的 css js 资源 -->
		<link rel="stylesheet" href="https://unpkg.com/element-ui@2.13.0/lib/theme-chalk/index.css">
		<link rel="stylesheet" href="../../static/sa.css">
		<script src="https://unpkg.com/vue@2.6.10/dist/vue.js"></script>
		<script src="https://unpkg.com/element-ui@2.13.0/lib/index.js"></script>
		<script src="https://unpkg.com/http-vue-loader@1.4.2/src/httpVueLoader.js"></script>
		<script src="https://unpkg.com/jquery@3.4.1/dist/jquery.js"></script>
		<script src="https://www.layuicdn.com/layer-v3.1.1/layer.js"></script>
		<script src="../../static/sa.js"></script>
		<style type="text/css">
			.c-panel .el-form .c-label{width: 7em !important;}
			.c-panel .el-form .el-input, .c-panel .el-form .el-textarea__inner{width: 250px;}
		</style>
	</head>
	<body style="text-align: center">
		<div class="vue-box" :class="{sbot: id}" style="display: none;" :style="'display: block;'">
			<!-- ------- 内容部分 ------- -->
			<div class="s-body">
				<div class="c-panel">
					<sa-info name="客户姓名">{{m.custName}}</sa-info>
					<sa-info name="订单状态" :value="ss" type="enum" :jv="{1: '已结清[green]', 0: '未结清[red]'}"></sa-info>

					<el-switch
							v-model="ss"
							active-color="#13ce66"
							inactive-color="#ff4949">
					</el-switch>

					<sa-info name="订单总额" :value="m.totalPrice" type="money" br></sa-info>
					<div><el-tag effect="dark" type="success"> 已付金额</el-tag>
						<el-input-number v-model="m.amountPaid" :precision="2" :step="100" @change="HandlerChange"></el-input-number>元</div>

					<sa-info name="剩余应结" :value="m.unpaidAmount" type="money" br></sa-info>
				</div>
			</div>
			<!-- ------- 底部按钮 ------- -->
			<div class="s-foot">
				<el-button type="primary" @click="ok()">确定</el-button>
				<el-button @click="sa.closeCurrIframe()">取消</el-button>
			</div>
		</div>
        <script>
			
			var app = new Vue({
				components: {
					"sa-item": httpVueLoader('../../sa-frame/com/sa-item.vue'),
					"sa-info": httpVueLoader('../../sa-frame/com/sa-info.vue')
				},
				el: '.vue-box',
				data: {
					id: sa.p('id', 0),		// 获取超链接中的id参数（0=添加，非0=修改）
					m: {
					},		// 实体对象
					ss:false
				},
				methods: {
					HandlerChange:function (){
						this.m.unpaidAmount=this.m.totalPrice-this.m.amountPaid;
					},
					// 提交数据 
					ok: function(){
						this.m.status=this.ss;
						sa.ajax('/order/invoicing',this.m,function (res){
							sa.ok("结账成功！")
							parent.app.f5();		// 刷新父页面列表
							sa.closeCurrIframe();	// 关闭本页
						}.bind(this))

					},

				},
				mounted: function(){
					// 初始化数据
						sa.ajax('/order/getOrderMain/' + this.id, function(res) {
							this.m.orderId = this.id
							this.m.custName=res.data.custName
							this.ss=res.data.status
							this.m.totalPrice=res.data.totalPrice
							this.m.amountPaid=res.data.amountPaid
							this.m.unpaidAmount=res.data.unpaidAmount
							if(res.data == null) {
								sa.alert('未能查找到 id=' + this.id + " 详细数据");
							}
						}.bind(this))

				}
			})
			
		</script>
	</body>
</html>